<template>
  <div class="home_container">
    <van-nav-bar class="nav_bar">
      <van-button
        slot="title"
        icon="search"
        class="search_btn"
        round
        to="/search"
        >搜索</van-button
      >
    </van-nav-bar>
    <!-- 标签 -->
    <van-tabs v-model="active">
      <van-tab
        v-for="(item, index) in channels"
        :title="item.name"
        :key="index"
      >
        <!-- 组件 -->
        <articleList :channels="item" />
      </van-tab>
      <!-- 占位 -->
      <div slot="nav-right" class="demo">0</div>
      <!-- 编辑 -->
      <div
        slot="nav-right"
        class="wap_nav_wrap"
        @click="isChannelEditShow = true"
      >
        <van-icon name="wap-nav" class="wap_nav" />
      </div>
    </van-tabs>
    <!-- 弹出层 -->
    <van-popup
      v-model="isChannelEditShow"
      get-container="body"
      position="bottom"
      closeable
      close-icon-position="top-left"
      :style="{ height: '100%' }"
    >
      <channel-edit
        @handleChannelEditShow="isChannelEditShow = false"
        @updateActive="active = $event"
        :active="active"
      ></channel-edit>
    </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from "@/request/home";
import articleList from "./components/articleList";
import channelEdit from "./components/channelEdit";

export default {
  data() {
    return {
      active: 3,
      channels: [],
      isChannelEditShow: false
    };
  },
  components: { articleList, channelEdit },
  created() {
    this._getUserChannels();
  },
  methods: {
    async _getUserChannels() {
      const { data } = await getUserChannels();
      this.channels = data.data.channels;
    }
  }
};
</script>

<style lang="less" scoped>
.home_container {
  /deep/ .van-nav-bar__title {
    max-width: none;
  }
  .nav_bar {
    background-color: #3096fd;
    .search_btn {
      width: 277px;
      height: 32px;
      background-color: #5aacfe;
      border: none;
    }
  }
  .van-icon {
    font-size: 16px;
    color: white;
  }
  .van-button__text {
    font-size: 15px;
    color: white;
  }
  .demo {
    width: 50px;
    height: 44px;
  }
  .wap_nav_wrap {
    position: fixed;
    right: 0;
    line-height: 44px;
    background-color: #fff;
    .wap_nav {
      border-left: 1px solid #ccc;
      font-size: 25px;
      color: black;
    }
  }
}
</style>